class mpoint:
  x
  y
class Line:
  xArr
  yArr
  n
  visible
  Mode
  color
  yi
  yinum
class simpleLine:
  f
  l
  Mode
  k
  b
startTmp=[]
showYI=False
havepw=False
xformat=""
yformat=""
cl1 = 0xFF00
notNeedDelete=False
xgn=0
ygn=0
minx=-10
miny=-10
maxx=10
maxy=10
lminx=[]
lminy=[]
lmaxx=[]
lmaxy=[]
##  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  draging#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
draging=False
stx=0
sty=0
ex=0
ey=0 #  坐标
tx=0
ty=0
##  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  unZoom use#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
Dim ominx As Single, ominy As Single, omaxx As Single, omaxy As Single #  坐标
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
#  Dim x() As Variant, y() As Variant   #  信号线坐标数组
#  Dim n() As Long                    #  信号线点数数组

Dim l() As Line  #  信号线坐标数组,信号线点数数组

Dim zoomed As Boolean
Dim cl()  As Long            #  信号线颜色


Dim tmpLine() As mpoint      #  动态生成曲线的临时起点

Dim lineCount As Integer

Dim sline() As simpleLine
Dim slineCount As Integer

Dim first() As Long, last() As Long  #  显示特殊点
Dim showPeak As Boolean
Dim showPoint As Boolean
Dim incolor As Long  #  显示特殊点颜色
Dim ps As Integer  #  点大小
Dim v As String
Dim xdw As String
Dim ydw As String

Public Event myErr(num As Long, des As String)
Public Event zoomEV()
Public Event EVmscale()
#  Default Property Values:
#  Const m_def_hWnd = 0
#  Property Variables:
#  Dim m_hWnd As Long


Public Sub SETPWAXIS(b As Boolean)
Dim i As Integer
 For i = 0 To ygn - 1
            Label3(i).visible = b
            Line3(i).visible = b
 Next i
 havepw = b
End Sub
Public Sub setShowPoint(b As Boolean)
 showPoint = b
 draw
End Sub
Public Sub SetShowPeak(b As Boolean)
 showPeak = b
 draw
End Sub


Public Sub setRegion(f As Long, l As Long, i As Integer)
  first(i) = f
  last(i) = l
#    Call draw
End Sub
Public Sub setsimLinecount(a As Integer)
  slineCount = a
  ReDim sline(slineCount)
End Sub
Public Sub setLineCount(a As Long)
On Error GoTo merr
Dim i As Integer
  lineCount = a
  ReDim startTmp(a)
  ReDim lminx(a), lmaxx(a), lminy(a), lmaxy(a)
  #  ReDim x(a), y(a),n(a),
  ReDim l(a)
  ReDim cl(a), tmpLine(a), first(a), last(a)
  For i = 0 To lineCount - 1
     l(i).color = QBColor((i + 1) Mod 15)
     l(i).visible = True
     l(i).Mode = 0 #  0=line,1=point
  Next i
Exit Sub
merr:
 saveerrmsg
End Sub
Sub saveerrmsg()
 RaiseEvent myErr(Err.Number, Err.Description)
End Sub
Sub savelogmsg(s As String)
 RaiseEvent myErr(3333, s)
End Sub

Public Sub setArr(vx() As Single, vy() As Single, vn As Long, i As Integer)
#     x(i) = vx
#     y(i) = vy
#     n(i) = vn
   l(i).xArr = vx
   l(i).yArr = vy
   l(i).n = vn
   Command4.Enabled = True
#     Command4_Click  #  autofit
End Sub
Public Sub setSline(x1 As Single, Y1 As Single, X2 As Single, y2 As Single, i As Integer)
  sline(i).f.x = x1
  sline(i).f.y = Y1
  sline(i).l.x = X2
  sline(i).l.y = y2
  sline(i).Mode = 0 #  two point
End Sub
Public Sub setSlinekb(k As Single, b As Single, i As Integer)
  sline(i).k = k
  sline(i).b = b
  sline(i).Mode = 1 #  k b
End Sub
Public Function getLineVisible(i As Integer) As Boolean
    getLineVisible = l(i).visible
End Function

Public Sub setLineVisible(i As Integer, nv As Boolean)
If i < lineCount Then
  l(i).visible = nv
#    draw
End If
End Sub
Public Sub setlineColor(i As Integer, c As Long)
If i < lineCount Then
  l(i).color = c
#    draw
End If
End Sub
Public Sub setLineMode(i As Integer, vmode As Integer)
  l(i).Mode = vmode
 #   draw
End Sub

Public Sub setArrV(vx As Variant, vy As Variant, vn As Long, i As Integer)
#     x(i) = vx
#     y(i) = vy
#     n(i) = vn
   l(i).xArr = vx
   l(i).yArr = vy
   l(i).n = vn
   l(i).Mode = 0
   Debug.Print l(i).n
   Command4.Enabled = True
#     Command4_Click  #  autofit
End Sub

Public Sub init()
   Command1.Enabled = False
   Command2.Enabled = False
#     Dim i As Integer
#    setScale 0, 0, 50, 10
#    For i = 0 To lineCount - 1
#       l(i).n = 0
#    Next i
#     clear
#     lineCount = 0
End Sub
Sub mScale()
#  If miny < 0 Then
#      miny = 0
#  End If
#  If maxy > 5 Then maxy = 5
#  If minx < 0 Then minx = 0
RaiseEvent EVmscale
Picture1.Scale (minx, maxy)-(maxx, miny)
End Sub

Public Sub clear()
On Error GoTo merr
  If minx <> maxx And miny <> maxy Then
    mScale
    Picture1.Cls
    drawAxis
  Else
    savelogmsg "mcurve error scale"
  End If
Exit Sub
merr:
  saveerrmsg
End Sub
Public Sub shoushuo()
 shouShuoY
End Sub
Public Sub shouShuoXY()
On Error GoTo merr
 #  Call Picture1.PaintPicture(Picture1.Image, minX, minY, (maxX - minX), (maxY - minY), minX, minY, (maxX - minX) / 2, (maxY - minY) / 2, vbSrcCopy)
 #  BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
 Dim hb As Long
 hb = CreateSolidBrush(Picture1.BackColor)
 #  Dim hold As Long
 #  hold = SelectObject(Picture1.hdc, hb)
    Dim w As Integer, h As Integer
    Picture1.ScaleMode = 3
    w = Picture1.ScaleWidth:  h = Picture1.ScaleHeight
    StretchBlt Picture1.hdc, 0, h / 2, w / 2, h / 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    #  #  #  #  #  #  #  #  
    Dim r As RECT
    r.Left = 0: r.Top = 0: r.Right = w / 2 - 1: r.Bottom = h / 2
    Call FillRect(Picture1.hdc, r, hb)
    r.Left = w / 2: r.Top = 0: r.Right = w - 1: r.Bottom = h - 1
    Call FillRect(Picture1.hdc, r, hb)
  maxx = maxx + (maxx - minx)
  maxy = maxy + (maxy - miny)
  mScale
  drawAxis
#   Call SelectObject(Picture1.hdc, hold)
 #  picture1.
 Exit Sub
merr:
  saveerrmsg
End Sub
Public Sub shouShuoXY_()
On Error GoTo merr
 #  Call Picture1.PaintPicture(Picture1.Image, minX, minY, (maxX - minX), (maxY - minY), minX, minY, (maxX - minX) / 2, (maxY - minY) / 2, vbSrcCopy)
 #  BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
 Dim hb As Long
 hb = CreateSolidBrush(Picture1.BackColor)
 #  Dim hold As Long
 #  hold = SelectObject(Picture1.hdc, hb)
    Dim w As Integer, h As Integer
    Picture1.ScaleMode = 3
    w = Picture1.ScaleWidth:  h = Picture1.ScaleHeight
    StretchBlt Picture1.hdc, 0, 0, w / 2, h / 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    #  #  #  #  #  #  #  #  
    Dim r As RECT
    r.Left = 0: r.Top = h / 2: r.Right = w / 2 - 1: r.Bottom = h / 2
    Call FillRect(Picture1.hdc, r, hb)
    r.Left = w / 2: r.Top = 0: r.Right = w - 1: r.Bottom = h - 1
    Call FillRect(Picture1.hdc, r, hb)
  maxx = maxx + (maxx - minx)
  miny = miny - (maxy - miny)
  mScale
  drawAxis
#   Call SelectObject(Picture1.hdc, hold)
 #  picture1.
 Exit Sub
merr:
  saveerrmsg
End Sub

Public Sub shouShuoX()
On Error GoTo merr
 #  Call Picture1.PaintPicture(Picture1.Image, minX, minY, (maxX - minX), (maxY - minY), minX, minY, (maxX - minX) / 2, (maxY - minY) / 2, vbSrcCopy)
 #  BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
 Dim hb As Long
 hb = CreateSolidBrush(Picture1.BackColor)
 #  Dim hold As Long
 #  hold = SelectObject(Picture1.hdc, hb)
    Dim w As Integer, h As Integer
    Picture1.ScaleMode = 3
    w = Picture1.ScaleWidth:  h = Picture1.ScaleHeight
    StretchBlt Picture1.hdc, 0, 0, w / 2, h, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    #  #  #  #  #  #  #  #  
    Dim r As RECT
    #  r.Left = 0: r.Top = 0: r.Right = w / 2 - 1: r.Bottom = h / 2 - 1
    #  Call FillRect(Picture1.hdc, r, hb)
    r.Left = w / 2: r.Top = 0: r.Right = w: r.Bottom = h
    #  ??????? w-1 or w
    Call FillRect(Picture1.hdc, r, hb)
#   Call SelectObject(Picture1.hdc, hold)
  maxx = maxx + (maxx - minx)
  mScale
  #  error when tmpaddpoint click fit
  drawAxis
  #  picture1.Scale
  Exit Sub
merr:
 saveerrmsg
End Sub
Public Sub shouShuoY()
On Error GoTo merr
 #  Call Picture1.PaintPicture(Picture1.Image, minX, minY, (maxX - minX), (maxY - minY), minX, minY, (maxX - minX) / 2, (maxY - minY) / 2, vbSrcCopy)
 #  BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
 Dim hb As Long
 hb = CreateSolidBrush(Picture1.BackColor)
 #  Dim hold As Long
 #  hold = SelectObject(Picture1.hdc, hb)
    Dim w As Integer, h As Integer
    Picture1.ScaleMode = 3
    w = Picture1.ScaleWidth:  h = Picture1.ScaleHeight
    StretchBlt Picture1.hdc, 0, h / 2, w, h / 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    #  #  #  #  #  #  #  #  
    Dim r As RECT
    #  r.Left = 0: r.Top = 0: r.Right = w - 1: r.Bottom = h / 2 - 1
    r.Left = 0: r.Top = 0: r.Right = w - 1: r.Bottom = h / 2
    Call FillRect(Picture1.hdc, r, hb)
    #  r.Left = w / 2 - 1: r.Top = 0: r.Right = w - 1: r.Bottom = h - 1
    #  Call FillRect(Picture1.hdc, r, hb)
#   Call SelectObject(Picture1.hdc, hold)
  maxy = maxy + (maxy - miny)
  mScale
  #  error when tmpaddpoint click fit
  drawAxis
Exit Sub
merr:
 saveerrmsg
End Sub
Public Sub BshouShuoY(b As Single)
On Error GoTo merr
 #  Call Picture1.PaintPicture(Picture1.Image, minX, minY, (maxX - minX), (maxY - minY), minX, minY, (maxX - minX) / 2, (maxY - minY) / 2, vbSrcCopy)
 #  BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
 Dim hb As Long
 hb = CreateSolidBrush(Picture1.BackColor)
 #  Dim hold As Long
 #  hold = SelectObject(Picture1.hdc, hb)
    Dim w As Integer, h As Integer
    Picture1.ScaleMode = 3
    w = Picture1.ScaleWidth:  h = Picture1.ScaleHeight
    StretchBlt Picture1.hdc, 0, h * (1 - 1 / b), w, h / b, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    #  #  #  #  #  #  #  #  
    Dim r As RECT
    #  r.Left = 0: r.Top = 0: r.Right = w - 1: r.Bottom = h / 2 - 1
    r.Left = 0: r.Top = 0: r.Right = w - 1: r.Bottom = h * (1 - 1 / b)
    Call FillRect(Picture1.hdc, r, hb)
    #  r.Left = w / 2 - 1: r.Top = 0: r.Right = w - 1: r.Bottom = h - 1
    #  Call FillRect(Picture1.hdc, r, hb)
#   Call SelectObject(Picture1.hdc, hold)
  maxy = maxy + (maxy - miny) * (b - 1)
  mScale
  #  error when tmpaddpoint click fit
  drawAxis
Exit Sub
merr:
 saveerrmsg
End Sub

Public Sub shouShuoY_()
On Error GoTo merr
 #  Call Picture1.PaintPicture(Picture1.Image, minX, minY, (maxX - minX), (maxY - minY), minX, minY, (maxX - minX) / 2, (maxY - minY) / 2, vbSrcCopy)
 #  BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
 Dim hb As Long
 hb = CreateSolidBrush(Picture1.BackColor)
 #  Dim hold As Long
 #  hold = SelectObject(Picture1.hdc, hb)
    Dim w As Integer, h As Integer
    Picture1.ScaleMode = 3
    w = Picture1.ScaleWidth:  h = Picture1.ScaleHeight
    StretchBlt Picture1.hdc, 0, 0, w, h / 2, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    #  #  #  #  #  #  #  #  
    Dim r As RECT
    #  r.Left = 0: r.Top = 0: r.Right = w - 1: r.Bottom = h / 2 - 1
    r.Left = 0: r.Top = h / 2: r.Right = w - 1: r.Bottom = h
    Call FillRect(Picture1.hdc, r, hb)
    #  r.Left = w / 2 - 1: r.Top = 0: r.Right = w - 1: r.Bottom = h - 1
    #  Call FillRect(Picture1.hdc, r, hb)
#   Call SelectObject(Picture1.hdc, hold)
  miny = miny - (maxy - miny)
  mScale
  #  error when tmpaddpoint click fit
  drawAxis
Exit Sub
merr:
 saveerrmsg
End Sub
Public Sub BshouShuoY_(b As Single)
On Error GoTo merr
 #  Call Picture1.PaintPicture(Picture1.Image, minX, minY, (maxX - minX), (maxY - minY), minX, minY, (maxX - minX) / 2, (maxY - minY) / 2, vbSrcCopy)
 #  BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
 Dim hb As Long
 hb = CreateSolidBrush(Picture1.BackColor)
 #  Dim hold As Long
 #  hold = SelectObject(Picture1.hdc, hb)
    Dim w As Integer, h As Integer
    Picture1.ScaleMode = 3
    w = Picture1.ScaleWidth:  h = Picture1.ScaleHeight
    StretchBlt Picture1.hdc, 0, 0, w, h / b, Picture1.hdc, 0, 0, w, h, vbSrcCopy
    #  #  #  #  #  #  #  #  
    Dim r As RECT
    #  r.Left = 0: r.Top = 0: r.Right = w - 1: r.Bottom = h / 2 - 1
    r.Left = 0: r.Top = h / b: r.Right = w - 1: r.Bottom = h
    Call FillRect(Picture1.hdc, r, hb)
    #  r.Left = w / 2 - 1: r.Top = 0: r.Right = w - 1: r.Bottom = h - 1
    #  Call FillRect(Picture1.hdc, r, hb)
#   Call SelectObject(Picture1.hdc, hold)
  miny = miny - (maxy - miny) * (b - 1)
  mScale
  #  error when tmpaddpoint click fit
  drawAxis
Exit Sub
merr:
 saveerrmsg
End Sub

Public Sub draw()
#  #  debug.print "draw"
On Error GoTo merr
  Dim i As Integer
  clear  #  drawaxis
  Debug.Print "clear"
#    #  debug.print "draw:"
  For i = 0 To lineCount - 1
   #  Call drawLine(x(i), y(i), n(i), cl(i), i)
   If l(i).visible Then
#     #  debug.print i
   If l(i).Mode = 0 Then
     #  line
     Call drawLine(l(i).xArr, l(i).yArr, l(i).n, l(i).color, i)
   ElseIf l(i).Mode = 1 Then
     #  point
     Call drawLineWithpoint(l(i).xArr, l(i).yArr, l(i).n, l(i).color, i)
   ElseIf l(i).Mode = 2 Then
     Call drawLineAndPoint(l(i).xArr, l(i).yArr, l(i).n, l(i).color, i)
   End If
   End If
   Debug.Print i, l(i).n
  Next i
  For i = 0 To slineCount - 1
#      #  debug.print i
    If sline(i).Mode = 0 Then
        Picture1.Line (sline(i).f.x, sline(i).f.y)-(sline(i).l.x, sline(i).l.y)
        #  #  debug.print "sline", sline(i).f.x, sline(i).f.y, sline(i).l.x, sline(i).l.y
    ElseIf sline(i).Mode = 1 Then
        Picture1.Line (minx, minx * sline(i).k + sline(i).b)-(maxx, maxx * sline(i).k + sline(i).b)
    End If
  Next i
#    #  debug.print "end draw"
Exit Sub
merr:
 saveerrmsg
End Sub

Public Sub setScale(vminx As Single, vminy As Single, vmaxx As Single, vmaxy As Single)
   minx = vminx
   miny = vminy
   maxx = vmaxx
   maxy = vmaxy
#     Call draw
End Sub

Sub setGridnumber(vxgn As Single, vygn As Single)
On Error GoTo merr
Dim i As Integer
Dim a As Integer
  xgn = vxgn: ygn = vygn
  a = Label1.Count
  If a < ygn Then
    For i = a To ygn - 1
        Load Label1(i): Label1(i).visible = True
        #  label1(i).Alignment=1#  right align
        Load Line1(i): Line1(i).visible = True
        #  #  #  #  #  #  
        Load Label3(i)
        Load Line3(i)
        If havepw Then
            Label3(i).visible = True
            Line3(i).visible = True
        End If
        
    Next i
  End If
  a = Label2.Count
  If a < xgn Then
    For i = a To xgn - 1
        Load Label2(i): Label2(i).visible = True
        Load Line2(i): Line2(i).visible = True
        
    Next i
  End If
  #  #  #  debug.print Label1.count, Label2.count
#    Stop
Exit Sub
merr:
 saveerrmsg
End Sub
Public Sub vertline(x1 As Single)
 Picture1.Line (x1, minx)-(x1, maxx), cl1
End Sub
Public Sub rawLine(x1 As Single, Y1 As Single, X2 As Single, y2 As Single)
  Picture1.Line (x1, Y1)-(X2, y2)
End Sub
Public Sub drawLine(x11 As Variant, y11 As Variant, countvolt As Long, c As Long, li As Integer)
On Error GoTo merr
Dim r As Single
Dim num As Long, px As Single, py As Single
#    #  #  debug.print "drawline"
#    #  #  debug.print countvolt
  r = Picture1.ScaleX(ps, vbPixels, vbUser)
  Dim i As Long
  If countvolt < 1 Then Exit Sub #  no data
  #  drawAxis
  #  mscale
  #  Picture1.Cls
  #  Picture1.Circle (x(0), y(0)), r, c
#    Picture1.FillStyle = 0
#    Picture1.FillStyle = 0
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
  #  Call myDrawPoint(li, 0, x11(0), Y11(0), c, r)
#    Picture1.ForeColor = c
  num = 0: px = x11(num): py = y11(num)
#    If showPeak Then
#  #    If num >= first(li) And num <= last(li) Then
#  #           Picture1.FillColor = incolor
#  #    Else
#  #           Picture1.FillColor = c
#  #    End If
#    Else
#    End If
  #  Picture1.Line -(px, py)
  #  #  #  debug.print x(num), Y(num)
  #  Picture1.Circle (px, py), r, c
  Picture1.PSet (px, py), c
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
  #  Picture1.FillStyle = 0
  #  #  #  debug.print countvolt
 For i = 1 To countvolt - 1 #   0 to countVolt-1
      #  Call myDrawPoint(li, i, CSng(x11(i)), CSng(Y11(i)), c, r)
        px = x11(i): py = y11(i): num = i
       If showYI Then
            Picture1.Line -(px, py)
            If inArr(num, l(li).yi, l(li).yinum) Then
              Picture1.FillColor = incolor
              Picture1.Circle (px, py), r, incolor
            Else
              Picture1.FillColor = c
              Picture1.Circle (px, py), r, c
            End If
            Picture1.PSet (px, py)
       Else
            If showPeak And num >= first(li) And num <= last(li) Then
#                Debug.Print "inpeak", num
              Picture1.Line -(px, py), incolor
            Else
              Picture1.Line -(px, py), c
            End If
       End If
     Next i
     Exit Sub
merr:
  saveerrmsg
#   #  when zoom to  too min region ,it overflow
#   #  MsgBox Err.Description, , Str(Err.Number)
#   RaiseEvent myErr(Err.Number, Err.Description)
End Sub
Private Sub drawLineWithpoint(x11 As Variant, y11 As Variant, countvolt As Long, c As Long, li As Integer)
On Error GoTo merr
Dim r As Single
Dim num As Long, px As Single, py As Single
#    #  #  debug.print "drawline"
#    #  #  debug.print countvolt
  r = Picture1.ScaleX(ps, vbPixels, vbUser)
  Dim i As Long
  If countvolt < 1 Then Exit Sub #  no data
  #  drawAxis
  #  mscale
  #  Picture1.Cls
  #  Picture1.Circle (x(0), y(0)), r, c
  Picture1.FillStyle = 0
  Picture1.FillStyle = 0
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
  #  Call myDrawPoint(li, 0, x11(0), Y11(0), c, r)
  Picture1.ForeColor = c
  num = 0: px = x11(num): py = y11(num)
  If showPeak Then
  If num >= first(li) And num <= last(li) Then
         Picture1.FillColor = incolor
  Else
         Picture1.FillColor = c
  End If
  Else
  End If
  #  Picture1.Line -(px, py)
  #  #  #  debug.print x(num), Y(num)
  Picture1.Circle (px, py), r, c
  #  Picture1.PSet (px, py)
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
  #  Picture1.FillStyle = 0
  #  #  #  debug.print countvolt
  If showPeak Then
  For i = 1 To countvolt - 1 #   0 to countVolt-1
    #  Call myDrawPoint(li, i, CSng(x11(i)), CSng(Y11(i)), c, r)
    px = x11(i): py = y11(i): num = i
      #  Picture1.Line -(px, py)
      If num >= first(li) And num <= last(li) Then
        #  Picture1.FillColor = incolor
        Picture1.ForeColor = incolor
        Picture1.Circle (px, py), r, incolor
      Else
        #  Picture1.FillColor = c
        Picture1.ForeColor = c
        Picture1.Circle (px, py), r, c
      End If
      #  Picture1.PSet (px, py)
   Next i
   Else
      For i = 1 To countvolt - 1 #   0 to countVolt-1
     #  Call myDrawPoint(li, i, CSng(x11(i)), CSng(Y11(i)), c, r)
       px = x11(i): py = y11(i): num = i
       #  Picture1.Line -(px, py)
       #  Picture1.PSet (px, py)
       Picture1.Circle (px, py), r, c
      Next i
   End If
Exit Sub
merr:
#   #  when zoom to  too min region ,it overflow
#   #  MsgBox Err.Description, , Str(Err.Number)
#   RaiseEvent myErr(Err.Number, Err.Description)
  saveerrmsg
End Sub

Sub myDrawPoint(li As Integer, num As Long, px As Single, py As Single, c As Long, r As Single)
On Error GoTo merr
If showYI Then
  Picture1.Line -(px, py)
  If inArr(num, l(li).yi, l(li).yinum) Then
    Picture1.FillColor = incolor
    Picture1.Circle (px, py), r, incolor
  Else
    Picture1.FillColor = c
    Picture1.Circle (px, py), r, c
  End If
  Picture1.PSet (px, py)
Else
  Picture1.Line -(px, py)
  If num >= first(li) And num <= last(li) Then
    Picture1.FillColor = incolor
    Picture1.Circle (px, py), r, incolor

  Else
    Picture1.FillColor = c
    Picture1.Circle (px, py), r, c

  End If
  Picture1.PSet (px, py)
End If
Exit Sub
merr:
  saveerrmsg
End Sub
Public Sub drawPoint(x As Single, y As Single)
  Picture1.PSet (x, y), cl1
End Sub

Public Sub startTmpLine(x As Single, y As Single, i As Integer)
If l(i).visible = False Then
  tmpLine(i).x = x: tmpLine(i).y = y
  Exit Sub
End If
If Not startTmp(i) Then
    startTmp(i) = True
    If x < minx Then
      minx = x
    ElseIf x > maxx Then
      maxx = x
    End If
    If y < miny Then
      miny = y
    ElseIf y > maxy Then
      maxy = y
    End If
      #  Call setScale(minx, ymin, xmax, ymax)
      drawAxis
      #  picture1.PaintPicture(picture1.Picture ,minx
      Picture1.PSet (x, y), l(i).color
      tmpLine(i).x = x: tmpLine(i).y = y
Else
    #  first point but shousuo
    If x > maxx Then
      If y > maxy Then
        #  debug.print "shoushuo xy"
        shouShuoXY
      ElseIf y < miny Then
        #  debug.print "shoushuo xy _"
        shouShuoXY_
      Else
       shouShuoX
      End If
    Else
        Debug.Print "x<maxx"
        If y > maxy Then
            shouShuoY
            Debug.Print "shoushuo y"
        ElseIf y < miny Then
            shouShuoY_
            Debug.Print "shoushuo y-"
        End If
    End If
    Picture1.PSet (x, y), l(i).color
    tmpLine(i).x = x: tmpLine(i).y = y
End If
End Sub

Public Sub TmpLineAddPoint(x As Single, y As Single, i As Integer)
If l(i).visible = False Then
  tmpLine(i).x = x: tmpLine(i).y = y
  Exit Sub
End If
Dim b As Single
    #  first point but shousuo
    If x > maxx Then
      If y > maxy Then
        #  debug.print "shoushuo xy"
        shouShuoXY
      ElseIf y < miny Then
        #  debug.print "shoushuo xy _"
        shouShuoXY_
      Else
       shouShuoX
      End If
    Else
        If y > maxy Then
            shouShuoY
            #  debug.print "shoushuo y"
        ElseIf y < miny Then
            shouShuoY_
            #  debug.print "shoushuo y-"
        End If
    End If
  Picture1.PSet (tmpLine(i).x, tmpLine(i).y), l(i).color
  Picture1.Line -(x, y), l(i).color
  tmpLine(i).x = x: tmpLine(i).y = y
End Sub

#  Public Sub drawLineTo(x As single, y As single)
#   Picture1.Line -(x, y), cl
#  End Sub
Private Sub drawAxis()
On Error GoTo merr
RaiseEvent zoomEV
Dim i As Long
Dim w As Long
Dim j As Long
Dim xj As Long
w = Abs(Line1(0).X2 - Line1(0).x1) #  线段长
j = Picture1.height / (ygn - 1)       #  y 间隔
  For i = 0 To ygn - 1
    Label1(i).height = 255
    Label1(i).Caption = Format((miny + i * (maxy - miny) / CSng(ygn - 1)), yformat) + ydw
    #  debug.print i, Label1(i).Caption
    Line1(i).x1 = Picture1.Left: Line1(i).X2 = Line1(i).x1 - w
    Line1(i).Y1 = Picture1.Top + Picture1.height - i * j: Line1(i).y2 = Line1(i).Y1
    Label1(i).Left = 0
    Label1(i).width = Line1(i).x1
    Label1(i).Top = Line1(i).y2 - Label1(i).height * 0.9 #   / 2
    Label1(i).Refresh
    Call Line1(i).ZOrder(0)
#      If havepw Then
        Label3(i).height = 255
        Label3(i).Caption = Format((0 + i * (6 - 0) / CSng(ygn - 1)), "0") + "kW"
        #  debug.print i, Label1(i).Caption
        Line3(i).x1 = Picture1.Left + Picture1.width
        Line3(i).X2 = Line3(i).x1 + w
        Line3(i).Y1 = Picture1.Top + Picture1.height - i * j: Line3(i).y2 = Line3(i).Y1
        
        Label3(i).Left = Picture1.Left + Picture1.width
        Label3(i).width = UserControl.width - Label3(i).Left
        Label3(i).Top = Line3(i).y2 - Label3(i).height * 0.9 #   / 2
        Label3(i).Refresh
        Call Line3(i).ZOrder(0)
#      End If
  Next i
xj = Picture1.width / (xgn - 1)
w = w / 2     #  x line --
  For i = 0 To xgn - 1
    Label2(i).width = 500
    Label2(i).height = 255
    Label2(i).Caption = Format((minx + i * (maxx - minx) / CSng(xgn - 1)), xformat) + xdw
    Line2(i).x1 = Picture1.Left + i * xj: Line2(i).X2 = Line2(i).x1
    Line2(i).Y1 = Picture1.Top + Picture1.height: Line2(i).y2 = Line2(i).Y1 + w
    Label2(i).Left = Line2(i).X2 - Label2(i).width / 2
    Label2(i).Top = Line2(i).y2 #  
    Label2(i).Refresh
  Next i
Exit Sub
merr:
 saveerrmsg
End Sub

Private Sub Command1_Click()
   If stx <> ex And sty <> ey Then
     Command2.Enabled = True
     Command1.Enabled = False
     zoomed = True
     notNeedDelete = True
     ominx = minx: ominy = miny: omaxx = maxx: omaxy = maxy
     Call setScale(stx, sty, ex, ey)
     Call draw
   End If
End Sub

Private Sub Command2_Click()
  notNeedDelete = True
  Command2.Enabled = False
  Command1.Enabled = True
  Call setScale(ominx, ominy, omaxx, omaxy)
  Call draw
End Sub

Public Sub fit()
On Error GoTo merr
notNeedDelete = True
Dim i As Integer
Dim truec As Long
For i = 0 To lineCount - 1
 If l(i).n <> 0 And l(i).visible Then
    lminx(truec) = longminV(l(i).xArr, l(i).n)
    lminy(truec) = longminV(l(i).yArr, l(i).n)
    lmaxx(truec) = longmaxV(l(i).xArr, l(i).n)
    lmaxy(truec) = longmaxV(l(i).yArr, l(i).n)
    truec = truec + 1
 End If
Next i
Dim minx1 As Double
Dim miny1 As Double
Dim maxx1 As Double
Dim maxy1 As Double
  minx1 = min(lminx(), truec)
  miny1 = min(lminy(), truec)
  maxx1 = max(lmaxx(), truec)
  maxy1 = max(lmaxy(), truec)
If minx1 <> maxx1 Then
    minx = minx1
    maxx = maxx1
    minx = minx - (maxx - minx) * 1 / 10
    maxx = maxx + (maxx - minx) * 1 / 10
End If
If miny1 <> maxy1 Then
    miny = miny1
    maxy = maxy1
    miny = miny - (maxy - miny) * 1 / 10
    maxy = maxy + (maxy - miny) * 1 / 10
End If
  Call draw
Exit Sub
merr:
 saveerrmsg
End Sub
Private Sub Command4_Click()

 fit
End Sub

Private Sub Command5_Click()
Command5.Enabled = False
Call GetWindowScreenshot(UserControl.hwnd, App.Path & "\" & "ab.bmp")
Command5.Enabled = True
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
#  #  #  #  debug.print Button
    If Button = 1 Then
        draging = True
        Picture1.DrawMode = vbXorPen
        Picture1.DrawStyle = vbDash
        If zoomed Then
                zoomed = False
        Else
               If notNeedDelete Then
               Else
                Picture1.Line (stx, sty)-(ex, ey), cl1, B
               End If
        End If
        stx = x: sty = y: tx = stx: ty = sty
    End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
   If draging Then
       Picture1.Line (stx, sty)-(tx, ty), cl1, B
       tx = x: ty = y
       Picture1.Line (stx, sty)-(x, y), cl1, B
   End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    If draging Then
       Command1.Enabled = True
       draging = False
       Picture1.DrawMode = vbCopyPen
       Picture1.DrawStyle = vbSolid
       ex = x: ey = y
       If stx > ex Then Call swap(stx, ex)
       If sty > ey Then Call swap(sty, ey)
       notNeedDelete = False
       #  Text1.Text = Str(sx) + "," + Str(sy) + "," + Str(ex) + "," + Str(ey)
    End If
End Sub


Private Sub Picture1_Paint()
#  debug.print Time$ + "draw line paint"
   draw
End Sub

Private Sub UserControl_Initialize()
  #  showPeak = True
  Picture1.BackColor = RGB(255, 255, 255)
  Call setGridnumber(6, 3)
  #  picture1.
  ps = 2
  xdw = "s": ydw = "v"
  xformat = "0": yformat = "0.00"
  minx = 0: maxx = 40: miny = -1: maxy = 1
  #  Picture1.Width = UserControl.Width * 0.8
  #  Picture1.Height = UserControl.Height * 0.8
  #  UserControl.Refresh
  #  Call setLineCount(2)
  mScale
  drawAxis
  incolor = RGB(0, 255, 0)
  #  Picture1.DrawWidth = 2
  Picture1.Cls
  Command4.Enabled = False
  Command1.Enabled = False
  Command2.Enabled = False
#    Command4.Caption = gtran.MyTranslate("显示全部", "Fit")
  If LANG = 0 Then
     Command4.Caption = "显示全部"
  Else
    Command4.Caption = "Fit"
  End If
End Sub

Private Sub UserControl_Paint()
#   draw
End Sub

Private Sub UserControl_Resize()
#  #  debug.print "mcurve resize"
#   If (UserControl.Width - Command1.Left * 1.5) > 0 Then
#      Picture1.Width = (UserControl.Width - Command1.Left * 1.5)
#   End If
#   If (UserControl.Height - Command1.Height * 2) > 0 Then
#      Picture1.Height = (UserControl.Height - Command1.Height * 2)
#   End If
Picture1.height = UserControl.height * 0.82
Picture1.Left = UserControl.width * 0.1
Picture1.Top = UserControl.height * 0.1
Picture1.width = UserControl.width * 0.85

Command5.height = UserControl.height * 0.1041667
Command5.Left = UserControl.width * 0.115
Command5.Top = UserControl.height * 0
Command5.width = UserControl.width * 0.06

Command1.height = UserControl.height * 0.1041667
Command1.Left = UserControl.width * 0.2
Command1.Top = UserControl.height * 0
Command1.width = UserControl.width * 0.06

Command2.height = UserControl.height * 0.1041667
Command2.Left = UserControl.width * 0.25
Command2.Top = UserControl.height * 0
Command2.width = UserControl.width * 0.06
Command3(0).height = UserControl.height * 0.1041667
Command3(0).Left = UserControl.width * 0.3966597
Command3(0).Top = UserControl.height * 0
Command3(0).width = UserControl.width * 0.08611691
Command3(1).height = UserControl.height * 0.1041667
Command3(1).Left = UserControl.width * 0.480167
Command3(1).Top = UserControl.height * 0
Command3(1).width = UserControl.width * 0.08611691
Command3(2).height = UserControl.height * 0.1041667
Command3(2).Left = UserControl.width * 0.605428
Command3(2).Top = UserControl.height * 0
Command3(2).width = UserControl.width * 0.08611691
Command3(3).height = UserControl.height * 0.1041667
Command3(3).Left = UserControl.width * 0.6889353
Command3(3).Top = UserControl.height * 0
Command3(3).width = UserControl.width * 0.08611691
Command4.height = UserControl.height * 0.1041667
Command4.Left = UserControl.width * 0.8
Command4.Top = UserControl.height * 0
Command4.width = UserControl.width * 0.12
drawAxis
End Sub
Private Sub Command3_Click(Index As Integer)
 #  minx = 0: maxx = 40: miny = -1: maxy = 1
 notNeedDelete = True
 Dim oldminx As Single
 Dim oldmaxx As Single
 Dim oldminy As Single
 Dim oldmaxy As Single
 oldminx = minx: oldminy = miny: oldmaxx = maxx: oldmaxy = maxy
Select Case Index
Case 1
  miny = (miny + maxy) / 2! - (maxy - miny)   #  计算精度不够
  maxy = (oldminy + oldmaxy) / 2! + (oldmaxy - oldminy)
Case 0
 miny = (miny + maxy) / 2 - (maxy - miny) / 4
    maxy = (oldminy + oldmaxy) / 2 + (oldmaxy - oldminy) / 4
Case 3            #  x-
 #  center  (minx+maxx)/2  r= (maxx-minx)/2
  #  minx = (minx + maxx) / 2! - (maxx - minx)   #  计算精度不够
  #  maxx = (oldminx + oldmaxx) / 2! + (oldmaxx - oldminx)
  maxx = maxx * 2  #  minx=0
Case 2             #  x+
    #  minx = (minx + maxx) / 2 - (maxx - minx) / 4
    #  maxx = (oldminx + oldmaxx) / 2 + (oldmaxx - oldminx) / 4
    maxx = maxx / 2 #  minx=0
End Select
Call draw
End Sub


Private Sub UserControl_Terminate()
 Dim i As Integer
 Dim a As Integer
 a = Label1.Count
 For i = 1 To a - 1
   Unload Label1(i)
   Unload Line1(i)
 Next i
 a = Label2.Count
 For i = 1 To a - 1
   Unload Label2(i)
   Unload Line2(i)
 Next i
End Sub




Public Sub drawLineAndPoint(x11 As Variant, y11 As Variant, countvolt As Long, c As Long, li As Integer)
On Error GoTo merr
Dim r As Single
Dim num As Long, px As Single, py As Single
#    #  #  debug.print "drawline"
#    #  #  debug.print countvolt
  r = Picture1.ScaleX(ps, vbPixels, vbUser)
  Dim i As Long
  If countvolt < 1 Then Exit Sub #  no data
  #  drawAxis
  #  mscale
  #  Picture1.Cls
  #  Picture1.Circle (x(0), y(0)), r, c
#    Picture1.FillStyle = 0
#    Picture1.FillStyle = 0
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
  #  Call myDrawPoint(li, 0, x11(0), Y11(0), c, r)
#    Picture1.ForeColor = c
  num = 0: px = x11(num): py = y11(num)
  If showPeak Then
#    If num >= first(li) And num <= last(li) Then
#           Picture1.FillColor = incolor
#    Else
#           Picture1.FillColor = c
#    End If
  Else
  End If
  #  Picture1.Line -(px, py)
  #  #  #  debug.print x(num), Y(num)
  Picture1.Circle (px, py), r, c
  Picture1.PSet (px, py), c
  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
  #  Picture1.FillStyle = 0
  #  #  #  debug.print countvolt
  If showPeak Then
    For i = 1 To countvolt - 1 #   0 to countVolt-1
      #  Call myDrawPoint(li, i, CSng(x11(i)), CSng(Y11(i)), c, r)
      px = x11(i): py = y11(i): num = i
        If num >= first(li) And num <= last(li) Then
          #  Picture1.FillColor = incolor
#            Picture1.ForeColor = incolor
          Picture1.Line -(px, py), incolor
          Picture1.Circle (px, py), r, incolor
        Else
          #  Picture1.FillColor = c
#            Picture1.ForeColor = c
          
          Picture1.Line -(px, py), c
          Picture1.Circle (px, py), r, c
        End If
        Picture1.PSet (px, py)
     Next i
   Else
      For i = 1 To countvolt - 1 #   0 to countVolt-1
     #  Call myDrawPoint(li, i, CSng(x11(i)), CSng(Y11(i)), c, r)
       px = x11(i): py = y11(i): num = i
       Picture1.Line -(px, py), c
       Picture1.Circle (px, py), r, c
       Picture1.PSet (px, py)
      Next i
   End If
 Exit Sub
merr:
  saveerrmsg
#   #  when zoom to  too min region ,it overflow
#   #  MsgBox Err.Description, , Str(Err.Number)
#   RaiseEvent myErr(Err.Number, Err.Description)
End Sub

Public Sub setxyformat(xf As String, yf As String)
 xformat = xf: yformat = yf
 drawAxis
End Sub
Public Sub setxyDw(x As String, y As String)
  xdw = x: ydw = y
End Sub

Public Sub setYiArr(yi1() As Long, yinum1 As Long, lini As Integer)
  l(lini).yi = yi1
  l(lini).yinum = yinum1
End Sub
Public Sub setbackcolor(c As Long)
 Picture1.BackColor = c
End Sub

def inArr(a , yi, num):
  inArr = False
  i=-1
  for i in range(num):# i = 0 To num - 1
    if yi(i) == a:
      return i
      break
   return i
#  


